package touro.finances.control;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import touro.finances.gui.ListExpenses;
import touro.finances.model.Expense;
import touro.finances.model.FinancesDatabase;

public class ListExpensesController implements ActionListener, ChangeListener{

	private FinancesDatabase fd;
	private ListExpenses expenses;
	
	public ListExpensesController(FinancesDatabase fd, ListExpenses expenses){
		this.fd = fd;
		this.expenses = expenses;
	}
	
	@Override
	public void actionPerformed(ActionEvent arg0) {
		try {
			expenses.setData(Expense.getExpenses(fd.getConnection(), fd));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		//expenses.validate();
		expenses.updateUI();
		
	}

	@Override
	public void stateChanged(ChangeEvent arg0) {
		//if JTabbedPane.selectedIndex =  1 //listExpenses
			//do same as actionPerformed
		
		
	}

}
